public class old_eq {
    public static int lib(int num, int den) {
        int ratio=0;
        if (num < 0 || den < 0) {
            ratio = -1;
        } else if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den > 200 || num > 200) {
            ratio = 200;
        } else if (den < 2) {
            ratio = 2 * num;
        } else if (den < 4) {
            ratio = num - den;
        } else if (den < 8) {
            if (num < den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 16) {
            if (num > den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 32) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 64) {
            ratio = 64;
            for (int i = 2; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 128) {
            int ratio1 = 0;
            int x = den, y = num, z = y;
            
            int limit = 0;
            int is1 = 0;
            if (num > 130) {
                ratio = 1;	
            }
            
            boolean denMoreThan80 = false;
            if (den < 80)	{
                for (int i = 1; i < den - 80; i++) {
                    z = x + y;
                    x = y;
                    y = z;
                }
            } else {
            
            }
            
            boolean denLessThan64 = false;
            if (den < 64) {
                ratio1 = z;
            }
            
            ratio += ratio1;
            
        } else {
            ratio = num + den + 10;
        }
        return ratio;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the numerator and denominator (e.g., 123 456): ");
        String input = scanner.nextLine();
        String[] parts = input.split(" ");
        int num = Integer.parseInt(parts[0]);
        int den = Integer.parseInt(parts[1]);
        int ratio = lib(num, den);
        System.out.println(ratio);
    }
}
